﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLHD.Models;
using QLHD.WS;
using QLHD.Utilities;

namespace QLHD
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            QLHD2013Entities db = new QLHD2013Entities();
            DateTime today = DateTime.Today;
            today = new DateTime(today.Year, today.Month, today.Day, 0, 0, 0);
            var hds = db.HopDongs.Where(q => q.ThoiGianNopBaoCao >= today && q.TrangThaiHD == 1 && (q.ParentID == null || q.ParentID == 0)).ToList();
            hdservice ut = new hdservice();
            List<int> viewphongbanids = ut.GetViewDepartmentIDs();
            hds.RemoveAll(q => q.DepartmentID != null && !viewphongbanids.Contains((int)q.DepartmentID));
            int cnt = hds.Where(q => q.CanhBaoTruoc != null && q.ThoiGianNopBaoCao <= today.AddDays((int)q.CanhBaoTruoc)).Count();
            if (cnt > 0)
            {
                divNotify.InnerText = string.Format(divNotify.InnerText, cnt);
            }
            else
            {
                divNotify.Visible = false;

            }
            NavigationMenu.Items[0].Enabled = false;
            NavigationMenu.Items[1].Enabled = false;
            NavigationMenu.Items[2].Enabled = false;
            NavigationMenu.Items[3].Enabled = false;
            NavigationMenu.Items[4].Enabled = false;
            if (Session["QLHD"] != null && Session["QLHD"].ToString() == "1")
                NavigationMenu.Items[0].Enabled = true;
            if (Session["QLPB"] != null && Session["QLPB"].ToString() == "1")
                NavigationMenu.Items[1].Enabled = true;
            if (Session["QLND"] != null && Session["QLND"].ToString() == "1")
                NavigationMenu.Items[2].Enabled = true;
            if (Session["TKBC"] != null && Session["TKBC"].ToString() == "1")
                NavigationMenu.Items[3].Enabled = true;
            if (Session["KCP"] != null && Session["KCP"].ToString() == "1")
                NavigationMenu.Items[4].Enabled = true;
            //if (!AuthenticationHelper.IsAdmin())
            //{
            //    NavigationMenu.Items[1].Enabled = false;
            //    NavigationMenu.Items[2].Enabled = false;
            //}
        }

        protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
